home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-12 | 4.5 KB | 135 lines | [TEXT/CWIE] |
- // LConsoleAttachment.h - Attachment which pumps events through SIOUX.
- /******************************************************************************\
- Copyright (c) 1995 by Ken Badertscher (KenBad@aol.com). All Rights Reserved.
-
- Permission to use, copy, modify, distribute and sell this software and its
- documentation for any purpose is hereby granted without fee, provided that
- the above copyright notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting documentation.
- Ken Badertscher makes no representations about the suitability of this software
- for any purpose. It is provided "as is" without express or implied warranty.
-
- USAGE NOTES:
- This class is useful for PowerPlant apps that want to use a console window
- for debugging info. In your LApplication subclass constructor, add
- an LConsoleAttachment like so:
- AddAttachment(new LConsoleAttachment("\pMy Console",
- LConsoleAttachment::kAutoClose,
- LConsoleAttachment::kNoAskSave));
- or use the handy AddConsoleAttachment macro to set up a default console.
-
- You need to do a couple of things to get the console window to coexist
- peaceably with your PowerPlant app:
-
- 1) Override AdjustCursor so that LEventDispatcher doesn't set an arrow
- cursor when the cursor is over an active console window. (LEventDispatcher
- really should do this for you--oh well.) This can be done like so:
- void MyApp::AdjustCursor(const EventRecord &inMacEvent)
- {
- EventRecord e = inMacEvent;
- if (LAttachable::ExecuteAttachments(msg_AdjustCursor, &e))
- inherited::AdjustCursor(inMacEvent);
- }
-
- 2) Use an StFlushSIOUX object in any function that writes to the console
- to ensure that the console window scroller is properly updated. As of
- this writing, SIOUX doesn't properly update scrollbars when output streams
- are flushed. Here's an example:
- void MyDebugFunction()
- {
- StFlushSIOUX flusher;
- cout << "debugging information" << endl;
- }
-
- That's all there is to it!
-
- Mail kudos & brickbats to KenBad@aol.com.
-
- History:
- 95-10-31 kbad Released it. Happy Halloween!
- 95-10-30 kbad Added command mapping to let SIOUX use app menus.
- 95-10-15 kbad Added auto-close flag
- 95-03-12 kbad Created
-
- TODO:
- \******************************************************************************/
-
- #pragma once
-
- #ifndef LCONSOLEATTACHMENT_H
- #define LCONSOLEATTACHMENT_H
-
- #include <LAttachment.h>
- #include <LCommander.h> // SCommandStatus
- #include <LString.h>
-
- // Macro to set up a default console attachment.
- //
- #define AddConsoleAttachment() AddAttachment(&gConsoleAttachment,nil,false)
-
- class StFlushSIOUX
- {
- /*============================================================================*\
- SIOUX console flusher - forces SIOUX to update scrollbars when exiting
- a scope. Instantiate one of these in a function that does console output
- to work around SIOUX bug where it doesn't update scroll bars until its
- window is activated.
- \*============================================================================*/
- public:
- StFlushSIOUX() {}
- ~StFlushSIOUX();
- };
-
-
- class LConsoleAttachment : public LAttachment
- {
- /*============================================================================*\
- Attachment which pumps events through SIOUX.
- \*============================================================================*/
- public:
- // I like my booleans to have meaningful names.
- enum EAutoClose {kNoAutoClose, kAutoClose};
- enum EAskSave {kNoAskSave, kAskSave};
-
- // Canonical members
- LConsoleAttachment(StringPtr title=0, EAutoClose=kAutoClose,
- EAskSave=kNoAskSave);
- virtual ~LConsoleAttachment();
-
- private:
- // no copying
- LConsoleAttachment(const LConsoleAttachment&);
- LConsoleAttachment& operator=(const LConsoleAttachment&);
-
- protected:
- // Framework overrides
- virtual void ExecuteSelf(MessageT inMessage, void *ioParam);
-
- private:
- // Implementation
- void FindCommandStatus(const SCommandStatus &status);
-
- void AdjustCursor(const EventRecord &inMacEvent);
- void DispatchEvent(const EventRecord& inMacEvent);
- void ObeyCommand(CommandT inCommand, void *ioParam);
- Boolean CommandKeyEvent(CommandT inCommand, EventRecord& e);
-
- Boolean SIOUXIsFront();
-
- TString<Str255> mTitle;
- Boolean mTitleSet;
-
- enum {kNumCommands = cmd_SelectAll+1};
- Boolean mCommandsCached;
- UInt32 mCommandKeyEvent[kNumCommands];
- };
-
- // Default console attachment, useful if no customization is needed.
- //
- extern LConsoleAttachment gConsoleAttachment;
-
- // LConsoleAttachment inlines
- //==============================================================================
-
- #endif //ndef LCONSOLEATTACHMENT_H
-